package com.amigo.online.common.util;

import java.math.BigDecimal;

public class DistanceHandleUtil {
	public final static String KM = "km";
	public final static String OVER_100KM = ">100";
	public final static String DEFAULT_0M = "0.01";
	/**
	 * 功能:大于 100km 100 精度10米
	 * 
	 * <p>
	 * 作者 zhaox 2018年9月7日 上午9:26:04
	 * 
	 * @param distance
	 * @return
	 */
	public static String convertDoubleToStringFormat(double distance) {
		StringBuilder result = new StringBuilder();
		if(distance <= 0) {
			result.append(DistanceHandleUtil.DEFAULT_0M);
		} else {
			BigDecimal bd = new BigDecimal(distance / 1000);
			result.append(bd.setScale(2, BigDecimal.ROUND_UP).doubleValue());
		}
		/*if ( distance > 0 && distance <= 100000) {
			BigDecimal bd = new BigDecimal(distance / 1000);
			result.append(bd.setScale(2, BigDecimal.ROUND_UP).doubleValue());
		} else {
			result.append(DistanceHandleUtil.OVER_100KM);
		}*/
		result.append(DistanceHandleUtil.KM);
		return result.toString();
	}
	
	
	public static void main(String[] args) {
		System.out.println(convertDoubleToStringFormat(-1.0));
		System.out.println(convertDoubleToStringFormat(0.0));
		System.out.println(convertDoubleToStringFormat(1.0));
		System.out.println(convertDoubleToStringFormat(77.0));
		System.out.println(convertDoubleToStringFormat(777.0));
		System.out.println(convertDoubleToStringFormat(7777.0));
		System.out.println(convertDoubleToStringFormat(77777.0));
		System.out.println(convertDoubleToStringFormat(777777.0));
		System.out.println(convertDoubleToStringFormat(7777777.0));
		System.out.println(convertDoubleToStringFormat(77777777.0));
		System.out.println(convertDoubleToStringFormat(777777777.0));
	}

}
